package com.bzkj.web.controller.wms;

import com.bzkj.basicinfo.domain.basic.WmsRuleEntity;
import com.bzkj.basicinfo.domain.basic.dto.WmsRuleDto;
import com.bzkj.basicinfo.service.basic.WmsRuleService;
import com.bzkj.common.annotation.LogC;
import com.bzkj.common.core.controller.BaseController;
import com.bzkj.common.core.domain.AjaxResult;
import com.bzkj.common.core.domain.BaseEntity;
import com.bzkj.common.core.domain.R;
import com.bzkj.common.core.page.TableDataInfo;
import com.bzkj.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Date 2025/01/13 20:14:58
 * @description 仓库规则
 */
@Api(tags = "规则管理")
@RestController
@RequestMapping("wms/rule")
public class WmsRuleController extends BaseController
{
    @Autowired
    private WmsRuleService wmsRuleService;


    /**
     * 获取所有规则
     *
     * @return
     */
    @ApiOperation("查询接口")
    @GetMapping("findRuleAll")
    public R findRuleAll()
    {
        return wmsRuleService.findRuleAll();
    }

    /**
     * 关联数据
     *
     * @param ruleId
     * @param association
     * @return
     */
    @ApiOperation("关联接口")
    @PostMapping("associationRule")
    @LogC(title = "规则信息", businessType = BusinessType.ASSOCIATION, pkFieldNames = "id",
            tableNames = "wms_rule_map"
    )
    public AjaxResult associationRule(@RequestBody WmsRuleDto dto, @RequestParam Integer type)
    {
        return wmsRuleService.associationRule(dto, type);
    }

    /**
     * 修改状态
     *
     * @param id
     * @return
     */
    @ApiOperation("关闭接口")
    @PutMapping("putRuleEnableStatus")
    public R putRuleEnableStatus(@RequestParam Integer id)
    {
        return wmsRuleService.putRuleEnableStatus(id);
    }


    /**
     * 获取规则类型
     *
     * @param type
     * @return
     */
    @ApiOperation("查看接口")
    @GetMapping("getRuleData")
    public TableDataInfo getRuleData(@RequestParam(value = "type") Integer type, BaseEntity entity)
    {
        startPage();
        return getDataTable(wmsRuleService.getRuleData(type));
    }

    /**
     * 保存规则信息
     *
     * @param wmsRuleEntity
     * @return
     */
    @ApiOperation("新增接口")
    @PostMapping("saveRuleInfo")
    @LogC(title = "规则信息", businessType = BusinessType.INSERT, pkFieldNames = "id",
            tableNames = "wms_rule",content = "' 规则名称：'+#wmsRuleEntity.ruleName"
    )
    public AjaxResult saveRuleInfo(@RequestBody WmsRuleEntity wmsRuleEntity)
    {
        return wmsRuleService.saveRuleInfo(wmsRuleEntity);
    }

    /**
     * 修改规则状态
     *
     * @param id
     * @return
     */
    @ApiOperation("停用接口")
    @PutMapping("putRuleInfo")
    @LogC(title = "规则信息", businessType = BusinessType.UPDATE, pkFieldNames = "id",
            tableNames = "wms_rule",detailTable = "wms_rule_map",detailPkField = "id",associatedIdField = "rule_id"
    )
    public R putRuleInfo(@RequestParam Integer id)
    {
        return wmsRuleService.putRuleInfo(id);
    }

    /**
     * 修改规则信息
     * @param wmsRuleEntity
     * @return
     */
    @ApiOperation("修改接口")
    @PutMapping("putRule")
    @LogC(title = "规则信息", businessType = BusinessType.UPDATE, pkFieldNames = "id",
            tableNames = "wms_rule",content = "'规则名称：'+#wmsRuleEntity.ruleName"
    )
    public R putRule(@RequestBody WmsRuleEntity wmsRuleEntity){
        return wmsRuleService.putRule(wmsRuleEntity);
    }

}